package com.hooya.fa.eu.biz.controller;

import com.hooya.fa.eu.api.dto.PlInvoiceFlushDTO;
import com.hooya.fa.eu.api.dto.PlInvoiceQueryDTO;
import com.hooya.fa.eu.biz.dao.entity.PlInvoice;
import com.hooya.fa.eu.biz.service.PLInvoiceService;
import com.hooya.integrated.common.core.util.R;
import com.hooya.integrated.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description 波兰开票
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2023/12/1
 * @Version 1.0.0
 */
@RestController
@RequiredArgsConstructor
@Tag(name = "pl发票")
@RequestMapping("/pl/invoice")
public class PLInvoiceController {

    private final PLInvoiceService plInvoiceService;

    @PostMapping("/add")
    @Inner(value = false)
    @Operation(summary = "新增波兰发票【√】", description = "新增波兰发票")
    public R<Void> addPLInvoice() {
        plInvoiceService.addPLInvoice();
        return R.ok();
    }

    @PostMapping("/add/correction")
    @Inner(value = false)
    @Operation(summary = "新增波兰修正发票【√】", description = "根据时间新增波兰修正发票")
    public R<Void> addCorrectionInvoice(@RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate) {
        plInvoiceService.addCorrectionInvoice(startDate, endDate);
        return R.ok();
    }

    @PostMapping("/flushInfo")
    @Inner(value = false)
    @Operation(summary = "刷写costway公司名称【√】", description = "刷写costway公司名称")
    public R<Void> flushInfo() {
        plInvoiceService.flushInfo();
        return R.ok();
    }

    @PostMapping("/temporaryFlushInfo")
    @Inner(value = false)
    @Operation(summary = "临时刷写发票信息", description = "临时刷写发票信息", hidden = true)
    public R temporaryFlushInfo(@RequestBody PlInvoiceFlushDTO dto) {
        return R.ok().setMsg(plInvoiceService.temporaryFlushInfo(dto));
    }

    @GetMapping("/getFlushInfo")
    @Inner(value = false)
    @Operation(summary = "获取需要刷写的波兰发票数据（local）", description = "根据条件获取需要对波兰发票系统刷写的数据")
    public R<List<PlInvoice>> getFlushInfo(PlInvoiceQueryDTO queryDTO) {
        return R.ok(plInvoiceService.getFlushInfo(queryDTO));
    }

    @PostMapping("/batch/delete")
    @Inner(value = false)
    @Operation(summary = "根据波兰发票id批量删除线上发票", description = "根据波兰发票id批量删除线上发票", hidden = true)
    public R<Void> batchDeleteByPlIds(@RequestParam("date") String date) {
        plInvoiceService.batchDeleteByPlIds(date);
        return R.ok();
    }

    @PostMapping("/number/batch/delete")
    @Inner(value = false)
    @Operation(summary = "按月批量删除线上发票", description = "按月批量删除线上发票(格式yyyy-MM-dd)", hidden = true)
    public R<Void> batchDeleteByNumber(@RequestParam("date") String date) {
        plInvoiceService.batchDeleteByNumber(date);
        return R.ok();
    }

    @PostMapping("/write/back")
    @Inner(value = false)
    @Operation(summary = "回写client id", description = "根据日期（当月月初），将波兰已有数据的client id进行回写", hidden = true)
    public R<Void> writeBackClientId(@RequestParam("date") String date) {
        plInvoiceService.writeBackClientId(date);
        return R.ok();
    }

}
